package top.haijunit.common.redis.domain;

import lombok.Data;

/**
 * redisson加锁配置
 *
 * @author zhanghaijun
 * @since 2024-07-31
 */
@Data
public class RedissonLockWrapper {

    /** 加锁key */
    private String lockKey;

    /** 获取锁的等待时间(单位ms, 值为-1时阻塞直到加锁成功) */
    private Long waitTime;

    /** 获取锁的执行时间(单位ms, 值为-1时阻塞直到加锁成功) */
    private Long leaseTime;

    public static RedissonLockWrapper lockWithDefaultTime(String lockKey) {
        RedissonLockWrapper lockConfigBO = new RedissonLockWrapper();
        lockConfigBO.setLockKey(lockKey);
        lockConfigBO.setWaitTime(RedissonConstant.DEFAULT_WAIT_TIME);
        lockConfigBO.setLeaseTime(RedissonConstant.DEFAULT_LEASE_TIME);
        return lockConfigBO;
    }

    public static RedissonLockWrapper lockWithUnlimitedTime(String lockKey) {
        RedissonLockWrapper lockConfigBO = new RedissonLockWrapper();
        lockConfigBO.setLockKey(lockKey);
        lockConfigBO.setWaitTime(RedissonConstant.UNLIMITED_TIME);
        lockConfigBO.setLeaseTime(RedissonConstant.UNLIMITED_TIME);
        return lockConfigBO;
    }
}
